package com.dao;

import com.pojo.Bill;
import com.utils.DSUtil;

import java.util.List;

public class BillDao {
    public List<Bill> queryAll() {
        return DSUtil.query("select * from bill",Bill.class);
    }

    public List<Bill> querySearch(String sql,Object...args) {
        return DSUtil.query(sql,Bill.class,args);
    }

    public void add(Bill bill) {
        DSUtil.execute("insert into bill (billCode,productName,unit,number,totalPrice,providerName,isPayment,creationDate) values (?,?,?,?,?,?,?,?)"
                ,bill.getBillCode(),bill.getProductName(),bill.getUnit(),bill.getNumber(),bill.getTotalPrice(),bill.getProviderName(),bill.getIsPayment(),bill.getCreationDate());
    }

    public Bill queryById(String id) {
        return DSUtil.query("select * from bill where id = ?",Bill.class,id).get(0);
    }

    public void update(Bill bill) {
        DSUtil.execute("update bill set billCode=?,productName=?,unit=?,number=?,totalPrice=?,providerName=?,isPayment=? where id=?",bill.getBillCode(),bill.getProductName(),bill.getUnit(),bill.getNumber(),bill.getTotalPrice(),bill.getProviderName(),bill.getIsPayment(),bill.getId());
    }

    public void removeById(String id) {
        DSUtil.execute("delete from bill where id = ?",id);
    }
}
